package com.inspur.cmis.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.inspur.cmis.pojo.User;
import com.inspur.cmis.service.UserService;

@Controller
public class LoginController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/login")
	public ModelAndView login(User user,HttpSession session){
		ModelAndView mv=new ModelAndView();
		//模拟admin/123456
//		//登陆正确
//		if("admin".equals(cname)&&"123456".equals(memPass)){
//			mv.addObject("success","欢迎您，登陆正确");
//			mv.setViewName("index.jsp");
//	    //登录失败
//		}else{
//			mv.addObject("error","用户登录信息不正确，请重填写");
//			mv.setViewName("login.jsp");
//		}
		
		//实际登录
		User checkUser=userService.getUser(user);
		System.out.println("roleId==="+checkUser.getRoleid());
		//登录成功
		if(null!=checkUser){
			session.setAttribute("user", checkUser);
			mv.setViewName("main.jsp");//迁移到main.jsp
		//登录失败
		}else{
			mv.addObject("error","用户登录信息不正确，请重填写");
			mv.setViewName("login.jsp");
		}
		
		return mv;
	}

}
